﻿using Microsoft.Extensions.DependencyInjection;
using System;

namespace WebMiddleware.Extensions
{
    /// <summary>
    /// 模块服务扩展。
    /// </summary>
    public static class ModuleServiceExtensions
    {
        /// <summary>
        /// 添加模块。
        /// </summary>
        /// <typeparam name="TModuleService">模块类型。</typeparam>
        /// <param name="services">服务收集器。</param>
        public static IServiceCollection AddModule<TModuleService>(this IServiceCollection services) where TModuleService : IModuleService, new()
        {
            var module = Activator.CreateInstance(typeof(TModuleService)) as IModuleService;
            module?.AddServices(services);
            return services;
        }
    }
}
